package edu.hawaii.senin.iclouds.statistics;

/**
 * Implements normal distribution within the class.
 * 
 * @author Administrator.
 * 
 */
public class NormalD {

  /**
   * Mean of the distribution.
   */
  private Double mean;

  /**
   * Standard deviation.
   */
  private Double sigma;

  /**
   * Constant to simplify calculations.
   */
  private Double const1;

  /**
   * NormalD constructor.
   * 
   * @param m mean.
   * @param s standard deviation.
   */
  public NormalD(Double m, Double s) {
    this.mean = m;
    this.sigma = s;
    this.const1 = 1 / (this.sigma * Math.sqrt(2 * Math.PI));
  }

  /**
   * Sts the new mean.
   * 
   * @param m new mean value.
   */
  public void setMean(Double m) {
    this.mean = m;
  }

  /**
   * Gets the mean.
   * 
   * @return distribution mean.
   */
  public Double getMean() {
    return this.mean;
  }

  /**
   * Sets new sigma.
   * 
   * @param s new sigma value.
   */
  public void setSigma(Double s) {
    this.sigma = s;
    this.const1 = 1 / (this.sigma * Math.sqrt(2 * Math.PI));
  }

  /**
   * Gets the standard deviation.
   * 
   * @return standard deviation value.
   */
  public Double getSigma() {
    return this.sigma;
  }

  /**
   * Returns probability value for specified x.
   * 
   * @param x parameter for computing.
   * @return probability value.
   */
  public Double getValue(Double x) {
    return const1 * Math.exp(-((x - this.mean) * (x - this.mean)) / (2 * this.sigma));
  }

}
